int cmd_sync(int argc, char **argv) { unsigned char key[KDF_HASH_LEN]; struct session *session = NULL; struct blob *blob = NULL; static struct option long_options[] = { {"background", no_argument, NULL, 'b'}, {"color", required_argument, NULL, 'C'}, {0, 0, 0, 0} }; int option; int option_index; bool background = false; while ((option = getopt_long(argc, argv, "b", long_options, &option_index)) != -1) { switch (option) { case 'b': background = true; break; case 'C': terminal_set_color_mode( parse_color_mode_string(optarg)); break; case '?': default: die_usage(cmd_sync_usage); } } init_all(0, key, &session, NULL); upload_queue_ensure_running(key, session); if (!background) { while (upload_queue_is_running()) usleep(1000000 / 3); } session_free(session); blob_free(blob); return 0; }
void upload_queue_enqueue(enum blobsync sync, unsigned const char key[KDF_HASH_LEN], const struct session *session, const char *page, struct http_param_set *params) { _cleanup_free_ char *sum = xstrdup(page); char *next = NULL; char *escaped = NULL; char *param; char **argv = params->argv; while ((param = *argv++)) { escaped = pinentry_escape(param); xasprintf(&next, "%s\n%s", sum, escaped); free(escaped); free(sum); sum = next; } upload_queue_write_entry(sum, key); if (sync != BLOB_SYNC_NO) upload_queue_ensure_running(key, session); }
void upload_queue_enqueue(enum blobsync sync, unsigned const char key[KDF_HASH_LEN], const struct session *session, const char *page, ...) { _cleanup_free_ char *sum = xstrdup(page); char *next = NULL; char *escaped = NULL; va_list params; char *param; va_start(params, page); while ((param = va_arg(params, char *))) { escaped = pinentry_escape(param); xasprintf(&next, "%s\n%s", sum, escaped); free(escaped); free(sum); sum = next; } va_end(params); upload_queue_write_entry(sum, key); if (sync != BLOB_SYNC_NO) upload_queue_ensure_running(key, session); }